//
//  SEGOrderPayListCell.m
//  SEGUhomePropertyBaseService
//
//  Created by Clavis on 2018/10/18.
//  Copyright © 2018 刘山. All rights reserved.
//

#import "SEGOrderPayListCell.h"

@interface SEGOrderPayListCell ()

@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIButton *checkBox;

@end
@implementation SEGOrderPayListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.icon = ({
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:imageView];
        imageView;
    });
    self.nameLabel = ({
        UILabel *lable = [[UILabel alloc] init];
        lable.font = kFont_17;
        lable.textColor = kColor_1;
        [self.contentView addSubview:lable];
        lable;
    });
    self.checkBox = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_tick_nor")] forState:UIControlStateNormal];
        [button setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_list_select")] forState:UIControlStateSelected];
        [button addTarget:self action:@selector(checkBoxClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:button];
        button;
    });
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(13);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(24);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.icon.mas_right).offset(15);
        make.centerY.equalTo(self.icon);
    }];
    [self.checkBox mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(44);
        make.top.right.bottom.equalTo(self.contentView);
    }];
    
}

- (void)updateCellWithModel:(SEGWorkOrderPayListModel *)model isSelect:(BOOL)isSelect {
    self.nameLabel.text = model.name;
    self.icon.image = nil;
    if ([model.code isEqualToString:@"MERGE"]) {
        self.icon.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_hebing_pay")];
    } else {
        [self.icon setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kClientImageRootURL, model.iconUrl]] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_70")]];
    }
    self.checkBox.selected = isSelect;
}

- (void)checkBoxClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (self.selectBlock) {
        self.selectBlock();
    }
}

@end
